<?php
require_once('./class/Responsable.php');
require_once('./class/Role.php');
require_once('./class/Association.php');
switch (@$_GET['action']){
    default:
        echo _RESPONSABLE_;
    break;

    case "list":
        $id_a = (isset($_GET['id_association'])) ? $_GET['id_association'] : null;
        $link = (isset($_GET['id_association'])) ? '<a href="?module=responsable&action=addForm&id_association='.$_GET['id_association'].'">'._ADD_RESPONSABLE_.'</a>' : '';
        $respo_array = Responsable::getAllResponsable($id_a);
        $html = $link.'
        		<table class="tablesorter">
        							<thead>
        								<th>'._ID_INDIVIDU_.'</th>
        								<th>'._NOM_INDIVIDU_.'</th>
        								<th>'._PRENOM_INDIVIDU_.'</th>
        								<th>'._EMAIL_ADHERENT_.'</th>
        								<th>'._FILIERE_ADHERENT_.'</th>
        								<th>'._PROMOTION_ADHERENT_.'</th>
        								<th>'._ID_ROLE_.'</th>
        								<th>'._ID_ASSOCIATION_.'</th>
        								<th>'._EDIT_.'</th>
        								<th>'._DELETE_.'</th>
        							</thead><tbody>';
        $i = 0;
        foreach($respo_array as $r){
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
        								<td>'.$r->getIdIndividu().'</td>
        								<td>'.$r->getNom().'</td>
        								<td>'.$r->getPrenom().'</td>
        								<td>'.$r->getEmail().'</td>
        								<td>'.$r->getFiliere().'</td>
        								<td>'.$r->getPromotion().'</td>
        								<td>'.Role::getRole($r->getIdRole())->getNom().'</td>
        								<td>'.Association::getAssociation($r->getIdAssociation())->getNom().'</td>
        							<td><a href="?module=responsable&action=modifyForm&id_individu='.$r->getIdIndividu().'&id_association='.$r->getIdAssociation().'">'._EDIT_.'</a></td>
        							<td><a href="?module=responsable&action=delete&id_individu='.$r->getIdIndividu().'&id_association='.$r->getIdAssociation().'">'._DELETE_.'</a></td>
        						</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;
        
    case "addForm":
        echo Responsable::getAddForm($_GET['id_association']);
    break;
    
    case "modifyForm":
        $r = Responsable::getResponsable($_GET['id_association'], $_GET['id_individu']);
        echo $r->getModifyForm();
    break;
    
    case "doAdd":
        $r = new Responsable();
        $r->setId($_POST['id_individu']);
        $r->setIdAssociation($_POST['id_association']);
        $r->setIdRole($_POST['id_role']);
        $r->addOrModify();
        echo _RESPONSABLE_.' '._ADDED_;
    break;
    
    case "doModify":
        $r = new Responsable();
        $r->setId($_POST['id_individu']);
        $r->setIdAssociation($_POST['id_association']);
        $r->setIdRole($_POST['id_role']);
        $r->addOrModify();
        echo _RESPONSABLE_.' '._MODIFIED_;
        break;
        
    case "delete":
        case "doAdd":
            $r = new Responsable();
            $r->setId($_GET['id_individu']);
            $r->setIdAssociation($_GET['id_association']);
            $r->delete();
            echo _RESPONSABLE_.' '._DELETED_;
            break;
}
?>
